//
//  MineShopController.m
//  ScalperMerchant
//
//  Created by 王云 on 2017/10/6.
//  Copyright © 2017年 WY. All rights reserved.
//

#import "MineShopController.h"
#define kMineHeaderH  kWidth*(400/750.0)

@interface MineShopController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak)UITableView *tableView;
@property (nonatomic,strong)NSArray *dataSouce;


@end

@implementation MineShopController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"我的店铺";
    [self setUI];
    [self initData];
}
- (void)initData{
    
    SCUser *user = [SCUserTool loadInfo];
       
    ZYPersonalInfoData *row1 = [ZYPersonalInfoData
                                dataWith:@"店铺名"
                                detitle:user.store_name
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row2 = [ZYPersonalInfoData
                                dataWith:@"入驻时间"
                                detitle:[HWCommon getTimeStr:@([user.joinin_time integerValue]) format:@"yyyy年MM月dd日"]
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row3 = [ZYPersonalInfoData
                                dataWith:@"店铺总额度"
                                detitle:user.credit_total
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row4 = [ZYPersonalInfoData
                                dataWith:@"已销售额度"
                                detitle:user.credit_coupon_sold
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row5 = [ZYPersonalInfoData
                                dataWith:@"已核销额度"
                                detitle:user.credit_coupon_consumed
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row6 = [ZYPersonalInfoData
                                dataWith:@"未分配总额度"
                                detitle:user.credit_undefined
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row7 = [ZYPersonalInfoData
                                dataWith:@"店铺电话"
                                detitle:user.member_mobile
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row8 = [ZYPersonalInfoData
                                dataWith:@"老板姓名"
                                detitle:user.boss_name
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row9 = [ZYPersonalInfoData
                                dataWith:@"老板电话"
                                detitle:user.store_phone
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row10 = [ZYPersonalInfoData
                                dataWith:@"店长姓名"
                                detitle:user.contacts_name
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row11 = [ZYPersonalInfoData
                                dataWith:@"店长电话"
                                detitle:user.contacts_phone
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row12 = [ZYPersonalInfoData
                                dataWith:@"经营类目"
                                detitle:user.gc_name
                                isRightA:NO
                                destVcClass:nil];
    ZYPersonalInfoData *row13 = [ZYPersonalInfoData
                                dataWith:@"黄牛派专属客服"
                                detitle:[NSString stringWithFormat:@"%@ %@",user.bd_name,user.bd_phone]
                                isRightA:NO
                                destVcClass:nil];

    
    self.dataSouce = @[@[row1,row2,row3,row4,row5,row6],@[row7,row8,row9,row10,row11,row12,row13]];
    
    [self.tableView reloadData];

}
- (void)setUI{
    
    __weak __typeof(&*self)weakSelf = self;
    
    UIView *baseHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kWidth , kMineHeaderH)];
    UIImageView *headerImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,kWidth , kMineHeaderH)];
    [headerImg sd_setImageWithURL:[NSURL URLWithString:[SCUserTool loadInfo].store_banner] placeholderImage:[UIImage imageNamed:@"home_back"]];

    [baseHeaderView addSubview:headerImg];
    self.tableView.tableHeaderView = baseHeaderView;
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arr = self.dataSouce[section];
    return arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identify"];
//    if (cell == nil) {
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"identify"];
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:13.0];

//    }
    if (indexPath.section == 0) {
        if (indexPath.row == 2) {
            cell.detailTextLabel.textColor = WYColor(48, 192, 86);
        }else if (indexPath.row == 3){
            cell.detailTextLabel.textColor = KOrange;
        }else if (indexPath.row == 4){
            cell.detailTextLabel.textColor = WYColor(228, 68, 67);
        }else if (indexPath.row == 0){
            
            UILabel *closeL = [[UILabel alloc] init];
            closeL.text =  @"审核通过";
            closeL.layer.cornerRadius = 3 ;
            closeL.layer.masksToBounds = YES;
            closeL.textColor = [UIColor whiteColor];
            [closeL setTextAlignment:NSTextAlignmentCenter];
            closeL.backgroundColor = WYColor(67, 190, 94);
            closeL.font = [UIFont systemFontOfSize:12];
            [cell.contentView addSubview:closeL];
            [closeL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(cell.contentView);
                make.right.equalTo(cell.detailTextLabel.mas_left).offset(-4);
                make.size.mas_equalTo(CGSizeMake(60, 20));
            }];

//            NSArray *rowArr = @[@"待审核",@"已审核",@"关闭"];
//            NSArray *colorArr = @[WYColor(67, 88, 191),WYColor(67, 190, 94),KOrange];
//            for (int i = 0; i < rowArr.count; i++) {
//                UILabel *closeL = [[UILabel alloc] init];
//                closeL.text =  rowArr[i];
//                closeL.layer.cornerRadius = 3 ;
//                closeL.layer.masksToBounds = YES;
//                closeL.textColor = [UIColor whiteColor];
//                [closeL setTextAlignment:NSTextAlignmentCenter];
//                closeL.backgroundColor = colorArr[i];
//                closeL.font = [UIFont systemFontOfSize:12];
//                closeL.backgroundColor = colorArr[i];
//                [cell.contentView addSubview:closeL];
//                [closeL mas_makeConstraints:^(MASConstraintMaker *make) {
//                    make.centerY.mas_equalTo(cell.contentView);
//                    make.right.equalTo(cell.detailTextLabel.mas_left).offset(-(4+i*40+i*4));
//                    make.size.mas_equalTo(CGSizeMake(40, 20));
//                }];
//            }
        }
    }
    ZYPersonalInfoData *data = self.dataSouce[indexPath.section][indexPath.row];
    cell.textLabel.text = data.title;
    cell.detailTextLabel.text = data.detitle;
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (UITableView *)tableView{
    
    if (_tableView == nil) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.separatorColor = WYColor(238, 238, 238);
        tableView.tableFooterView = [[UIView alloc] init];
//        [tableView registerNib:[UINib nibWithNibName:@"ClerkCell" bundle:nil] forCellReuseIdentifier:@"ClerkCell"];
        [self.view addSubview:tableView];
        _tableView = tableView;
    }
    return _tableView;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}



@end


@implementation ZYPersonalInfoData

+ (ZYPersonalInfoData *)dataWith:(NSString *)title
                         detitle:(NSString *)detitle
                        isRightA:(BOOL)isRightA
                     destVcClass:(__unsafe_unretained Class)destVcClass
{
    ZYPersonalInfoData *dd = [[ZYPersonalInfoData alloc]init];
    dd.title = title;
    dd.detitle = detitle;
    dd.isRightA = isRightA;
    dd.destVcClass = destVcClass;
    return dd;
    
}
@end

